#!/usr/bin/env python3
# -*- coding: utf-8 -*-

' String '

__author__ = 'dreamapple'

print('"Isn\'t," she said.')

# raw strings
print(r'C:\some\name')

# multiple lines
print("""\
Usage: thingy [OPTIONS]
     -h                        Display this usage message
     -H hostname               Hostname to connect to\
""")

print('hello world')

# strings can be concatenated (glued together) with the + operator, and repeated with *
print('hello' + ' world')
print('hello' + " world")

print(6 * 'a' + 'b')
print('a' * 6 + 'b')

# two or more string literals (i.e. the ones enclosed between quotes) next to each other are automatically concatenated.
print('hello'  'world')

# 字符串是可以被索引的
print('hello'[0])
print('hello'[1])

# 索引的值可以是负数，表示从字符串的尾部开始
print('hello'[-1])

# 字符串是可以进行切片的
print('hello'[:2])
print('hello'[2:])
print('hello'[:2] + 'hello'[2:])
print('hello'[-2:])

# attempting to use an index that is too large will result in an error
# print('hello'[10])

# out of range slice indexes are handled gracefully when used for slicing
print('hello'[:10])
print('hello'[10:])

# python strings cannot be changed — they are immutable. Therefore, assigning to an indexed position in the string results in an error
# 'hello'[0] = 'H'

print(len('hello'))